package ltd.hxya.novel.common.bean;

public class Result<T> {
    private Object msg;
    private Integer code;
    private  T data;



    /**
     * 成功，且有返回值
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> success(T data){
        return new Result<>(data);
    }

    /**
     * 执行成功，但没有返回值
     * @return
     */
    public static Result<Void> success(){
        return new Result<>();
    }

    /**
     * 失败，无返回值
     * @return
     */
    public static Result<Void> fail(Integer code,String msg){
        return new Result<>(code,msg);
    }

    //返回对象类型的错误信息
    public static Result fail(Integer code,Object msg){
        return  new Result(code,msg);
    }



    public Result(Integer code,String msg) {
        this.msg = msg;
        this.code = code;
    }

    public Result(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public Result(String msg, Integer code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public Result(T data) {
        this.data = data;
        this.code= ResultEnum.EXECUTE_SUCCESS.getCode();
        this.msg=ResultEnum.EXECUTE_SUCCESS.getMsg();
    }

    public Result() {
        this.code = ResultEnum.EXECUTE_SUCCESS.getCode();
        this.msg =ResultEnum.EXECUTE_SUCCESS.getMsg();
    }

    public Object getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
